class SceneManager extends egret.DisplayObjectContainer {
	public constructor() {
		super();
		this.startGameScene = new StartGameScene();
		// this.gameScene = new GameScene();
		this.chooseMode = new ChooseMode();
		this.dadian = new DaDian();
		this.selectLevel = new SelectLevel();
	}

	private static _instance: SceneManager;
	public static get Instance() {
		if (!SceneManager._instance) {
			SceneManager._instance = new SceneManager();
		}
		return SceneManager._instance;
	}
	private _stage: egret.DisplayObjectContainer;
	public startGameScene: StartGameScene;
	public gameScene: GameScene;
	public chooseMode: ChooseMode;
	public dadian: DaDian;
	public selectLevel: SelectLevel;
	/**
	 * 设置根场景
	 *
	 */
	public setStage(s: egret.DisplayObjectContainer) {
		this._stage = s;
	}

	/**
	 * 添加场景
	 */
	public addScene(scene: egret.DisplayObjectContainer, parent?: egret.DisplayObjectContainer) {
		if (parent) {
			parent.addChild(scene)
		} else {
			this._stage.addChild(scene);
		}
	}


	/**
	 * 移除场景
	 */
	public removeScene(scene: egret.DisplayObjectContainer, parent?: egret.DisplayObjectContainer) {
		if (parent) {
			parent.removeChild(scene)
		} else {
			this._stage.removeChild(scene);
		}
	}

	/**
	 * 切换场景
	 */
	public switchScene(scene: egret.DisplayObjectContainer, parent?: egret.DisplayObjectContainer) {
		if (parent) {
			parent.removeChildren();
			parent.addChild(scene);
		} else {
			this._stage.addChild(scene);
			scene.x = 640;
			egret.Tween.get(scene).to({ x: 0 }, 500);
			egret.Tween.get(this._stage.getChildAt(0)).to({ x: -640 }, 500).call(() => {
				if (this._stage.numChildren > 1) {
					this._stage.removeChildAt(0);
				}
			})
		}
	}
}

